package cn.tedu.egaddress0805.controller;

import cn.tedu.egaddress0805.mapper.AddressMapper;
import cn.tedu.egaddress0805.pojo.dto.AddressAddParam;
import cn.tedu.egaddress0805.pojo.entity.Address;
import cn.tedu.egaddress0805.pojo.vo.AddressListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {

    @Autowired
    private AddressMapper addressMapper;

    @PostMapping("add")
    public String addAddress(@RequestBody AddressAddParam addressAddParam) {
        System.out.println("添加地址：" + addressAddParam);
        int count = addressMapper.insertAddress(addressAddParam);
        return count>0?"添加地址成功！":"添加地址失败！";
    }

    @GetMapping("list")
    public List<AddressListVO> selectAddressList() {
        System.out.println("查询所有地址");
        return addressMapper.selectAddressList();
    }

    @PostMapping("del/{addressId}")
    public String deleteAddressById(@PathVariable("addressId") Integer id) {





        System.out.println("删除地址：" + id);
        int count = addressMapper.deleteAddressById(id);
        return count>0?"删除地址成功！":"删除地址失败！";
    }


}
